﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Treinamento2015_01Core.Models;
using Treinamento2015_01Core.Repository;

namespace Treinamento2015_01Core.Service
{
    public class ProductService : BaseService<Product, ProductRepository>
    {
        public ProductService()
            : base(new ProductRepository())
        { }

        public void SetAsInactive(Product product)
        {
            product.IsActive = false;
            _Repository.Update(product);
        }

        public List<Product> FindAllActives()
        {
            return _Repository.FindAllActives();
        }

        public override Product Create(Product product)
        {
            Stock stock = new Stock();
            stock.Product = product;
            stock.quantity = 0;
            Stock stockCreated=new StockService().Create(stock);
            return stockCreated.Product;
        }

        public void DeleteWithStock(Product product)
        {
            new StockService().Delete(new StockService().FindByProduct(product));
            this.SetAsInactive(product);
        }
    }
}
